unit URelatorioEmissaoEtiquetaMala;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, QuickRpt, QRCtrls, ExtCtrls, DB, DBTables;

type
  TFRelatorioEtiquetaMala = class(TForm)
    QuickRep1: TQuickRep;
    QRBand1: TQRBand;
    QRLNome: TQRLabel;
    QRLEndereco: TQRLabel;
    QRLCidade: TQRLabel;
    QRLBairro: TQRLabel;
    QRLCep: TQRLabel;
    QRLNome2: TQRLabel;
    QRLEndereco2: TQRLabel;
    QRLBairro2: TQRLabel;
    QRLCidade2: TQRLabel;
    QRLCep2: TQRLabel;
    QRelatorio: TQuery;
    ChildBand1: TQRChildBand;
    procedure QRBand1BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FRelatorioEtiquetaMala: TFRelatorioEtiquetaMala;
  controle : integer;

implementation

{$R *.dfm}

procedure TFRelatorioEtiquetaMala.QRBand1BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin

  { Controla o tamanho da banda filho! }
  QRBand1.Height:=67;
  inc(controle);
  if controle = 7 then
   begin
     controle:=0;
     ChildBand1.Height:=68;
   end
  else
   ChildBand1.Height:=ChildBand1.Height+3;

  { Alinha os QRlabels das colunas da esquerda e direita! }
  QRLNome.Top:=4;
  QRLNome2.Top:=4;
  QRLEndereco.Top:=20;
  QRLEndereco2.Top:=20;
  QRLBairro.Top:=38;
  QRLBairro2.Top:=38;
  QRLCidade.Top:=38;
  QRLCidade2.Top:=38;
  QRLCep.Top:=53;
  QRLCep2.Top:=53;

  { limpar os QRlabel da coluna da direita! }
  QRLNome2.Caption:='';
  QRLEndereco2.Caption:='';
  QRLBairro2.Caption:='';
  QRLCidade2.Caption:='';
  QRLCep2.Caption:='';



   if QRelatorio.FieldByName('TipoEndereco').AsString = '1' then
   begin
     QRLNome.Caption:=QRelatorio.FieldByName('Pessoa').AsString;
     QRLEndereco.Caption:=QRelatorio.FieldByName('EnderecoResp').AsString;
     QRLBairro.Caption:=QRelatorio.FieldByName('BairroResp').AsString;
     QRLCidade.Caption:=QRelatorio.FieldByName('CidadeResp').AsString + ' - ' + QRelatorio.FieldByName('UfResp').AsString;
     QRLCep.Caption:='CEP : ' +QRelatorio.FieldByName('CepResp').AsString;
   end
   else
    begin
     QRLNome.Caption:=QRelatorio.FieldByName('Pessoa').AsString;
     QRLEndereco.Caption:=QRelatorio.FieldByName('EnderecoPedi').AsString;
     QRLBairro.Caption:=QRelatorio.FieldByName('BairroPedi').AsString;
     QRLCidade.Caption:=QRelatorio.FieldByName('CidadePedi').AsString + ' - ' + QRelatorio.FieldByName('UfPedi').AsString;
     QRLCep.Caption:='CEP : ' +QRelatorio.FieldByName('CepPedi').AsString;
    end;


   QRelatorio.Next;
   if not QRelatorio.Eof then
    Begin
      if QRelatorio.FieldByName('TipoEndereco').AsString = '1' then
       begin
         QRLNome2.Caption:=QRelatorio.FieldByName('Pessoa').AsString;
         QRLEndereco2.Caption:=QRelatorio.FieldByName('EnderecoResp').AsString;
         QRLBairro2.Caption:=QRelatorio.FieldByName('BairroResp').AsString;
         QRLCidade2.Caption:=QRelatorio.FieldByName('CidadeResp').AsString + ' - ' + QRelatorio.FieldByName('UfResp').AsString;
         QRLCep2.Caption:='CEP : ' +QRelatorio.FieldByName('CepResp').AsString;
       end
       else
        begin
         QRLNome2.Caption:=QRelatorio.FieldByName('Pessoa').AsString;
         QRLEndereco2.Caption:=QRelatorio.FieldByName('EnderecoPedi').AsString;
         QRLBairro2.Caption:=QRelatorio.FieldByName('BairroPedi').AsString;
         QRLCidade2.Caption:=QRelatorio.FieldByName('CidadePedi').AsString + ' - ' + QRelatorio.FieldByName('UfPedi').AsString;
         QRLCep2.Caption:='CEP : ' +QRelatorio.FieldByName('CepPedi').AsString;
        end;
    end;
end;

end.
